
#pragma once
#include "CxType.h"
#include <algorithm>
#include <vector>
BEGIN_NAMESPACE(MSG_SIGN)

	BEGIN_NAMESPACE(utility)

	using std::vector;
class	CxImage
{
	typedef vector< vector<unsigned char>  >	_ImageData;
	
public:

	CxImage(int cx=512,int  cy=128):m_cx(cx),m_cy(cy),m_data(cy)
	{
		std::for_each(m_data.begin(),m_data.end(),
			[cx](_ImageData::reference p){p.resize(cx);});
	}




	bool		insert(size_t  line,const vector<unsigned char> &data)
	{
		if(line > m_data.size())return false;
		vector<unsigned char >  &src=m_data.at(line);
		if(data.size() != src.size())return false;

		if(m_cy<=64)
		{
			src.assign(data.begin(),data.end());
		}
		else 
		{
			for(int i=0;i!=src.size();++i)
			{
				src[i]=data[i] & 0x0F;
				if(line < m_cy-64)
					m_data.at(line+64)[i] = (data[i]>>4) & 0x0F;
			}
		}

		return true;
	}


	bool		getLine(size_t line,vector<unsigned char> &data)const
	{
		if(line > m_data.size())return false;
		data=m_data.at(line);
		return true;
	}
public:
	int			m_cx;
	int			m_cy;
	_ImageData  m_data;
};

	END_NAMESPACE

END_NAMESPACE


